#!./perl

# ------------------------------------------------------------

# visit_html.pl, by Jean-Pierre Girard (jpg@corrado.sun.com)
# This manages the main menu of the interface: the user is
# guided to do one step after another.

# ------------------------------------------------------------

# Bugs and other fixes

# ------------------------------------------------------------
##############################################################################
# CreatDefaultIndex: create a default index.html using _info file
##############################################################################
sub CreateDefaultIndex
{
	local($old);

	$INDEXFILENAME = "$HomeDir/$HomeName";
	unless (open (INDEXFILE, "> $INDEXFILENAME")) {
		&PrintErr("NoCreation", $INDEXFILENAME);
		#print "<H3><dd><img ALIGN=middle src=\"file:///tmp/httpd/.products/CDware/images/error.gif\">Cannot create $INDEXFILENAME</H3></dd><br>";
	}

	if (-s $INFOFILENAME && open (INFOFILE, $INFOFILENAME)) {
		$LINE=<INFOFILE>;
		($Company, $Description, $Platform, $ChosenCat, $WebSite, $Email) = split(/\^/, $LINE);
		$Product=<INFOFILE>;
		chop($Product);
		chop($Product);
		close (INFOFILE);
	}
	
	$old = select(INDEXFILE);
	#print "test\n";
	$~ = INDEX_DEFAULT;
	write;

	close(INDEXFILE);
	select($old);
}

##############################################################################
# main
##############################################################################
$BASEDIR = $ENV{"DOCUMENT_ROOT"};
require 'devinfo.pl';
require 'tools.pl';

$HomeDir = &GetDevinfo("dir");
$INFOFILENAME = $HomeDir . "/_info";

if ($ENV{'REQUEST_METHOD'} eq "POST") {
	read(STDIN, $request, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
	$request = $ENV{'QUERY_STRING'};
}
if (-s $INFOFILENAME && open (INFOFILE, $INFOFILENAME)) {
	$LINE=<INFOFILE>;
	($Company, $Description, $Platform, $Cat, $WebSite, $Email, $HomeName) = split(/\^/, $LINE);
	if ($HomeName eq "") {
		$HomeName = "index.html";
	}
	close (INFOFILE);
}

$~ = HEADER;
write;

$request =~ s/%(..)/pack("c",hex($1))/ge;
#print "request=$request<br>";
#print "ARGV0=$ARGV[0]<br>";
#if (@ARGV == 0 && $request eq "") {

if ($request eq "") {
	#print "in case argv=0";
} elsif ($request eq "default=Create") {
	#print "bef CreateDefault<br>";
	&CreateDefaultIndex();
} else {
	$OldHomeName=$HomeDir . "/" . $request;
	if (-s $OldHomeName) {
		if (!system("mv $OldHomeName $HomeDir/index.html")) {
			system("cd $HomeDir;ln -s ./index.html $OldHomeName");
		} else {
			&PrintErr("NoCreation", "$HomeDir/index.html");
		}
	} else {
		&PrintErr("NoExist", $OldHomeName);
	}
}

	unless (-s "$HomeDir/$HomeName") {
		print "<h4>\n<app class=\"ImageLoopItem\" img=\"file:///tmp/httpd/.products/DEV/images/blinkingAlert\" ALIGN=middle pause=5000 width=56 height=49>Your \"$HomeName\" file is missing!</h4><ul>"
		,"<H3><IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif\">If you already have HTML pages, copy them in the <b>\"$HomeDir\"</b> directory, and then reload the current page (press the <IMG ALIGN=middle SRC=\"file:///tmp/httpd/.products/DEV/images/sreload.gif\"> button at the page bottom).<br>"
		, "<IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif\">Otherwise, please press this button to create a default home page using the information you previously entered:"
		, "<FORM method=\"post\"  ACTION=\"http://localhost:7999/cgi-bin/visit_html.pl?\"><input type=\"submit\" NAME=\"default\" VALUE=\"Create\" > </FORM></ul></H3>"
	} else {
		$~ = ADVICES;
		write;
		#print "<H2><IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_pink.gif\"><a href=\"file://$HomeDir/$HomeName\">To test your main page and links</a></H2><br>";
		#print "<ul><IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/finger.gif\">To change your pages, you need to edit the html files that you put in the \"$HomeDir\" directory. To do that, you can use a text editor to directly change the content of the file or one of the numerous tools that exist.";
		#print "<p><IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/finger.gif\">If you visit your html pages, you can come back any time to the main menu of the Developer's Kit by using the \"Goto\" Menu.</ul><br>";
		#print "<H2><IMG ALIGN=middle src=\"file:///tmp/httpd/.products/DEV/images/bullet_ball_pink.gif\"><a href=\"file:///tmp/httpd/.products/DEV/tips.html\">Help and tips for designing your insertion</a></H2></ul><br>";
			##print "<H2><li><a href=\"http://localhost:7999/cgi-bin/checklinks.pl\">To check automatically your links</a></H2><br>";
	}

	$~ = FOOTER;
	write;

	$~ = SUBPAGE;
	write;


##############################################################################
# formats
##############################################################################
format HEADER =
Content-type: text/html


<html>
<title>Developer's Kit - HTML Test</title>
<body>
<CENTER><h1>CDware Developer's Kit</h1></CENTER>
<h4>Currently working with "@*
$HomeDir
" directory</h4>
<p>
<ol type=1>
.

format FOOTER =
</ol>
<h4><IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif"><a href="http://localhost:7999/cgi-bin/mainmenu.pl?">To go back to the main menu</a></h4><br>
<hr>
<p>
You, like these companies, will benefit from the CDware capability of reaching tens of thousands of potential customers with information, links to your web site, or directly with YOUR product!
<p><app class=ImageTape width=596 height=65 img_dir=../../../DEV/logos speed=10 dir=-10
url1=oracle
url2=progress
url3=gupta
url4=informix
url5=lotus
url6=ingres
>
</b>
<h5>If you have any comments or noticed some abnormal behavior, send us an Email: <A HREF="mailto:cdware@sun.com">cdware@sun.com</A> or call us at (415) 336-3941.</h5>
"@", "@"
<h5><p><A HREF=file:///tmp/httpd/.products/CDware/Help/SMICopyright.html>Copyright</A> 1995 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043 USA.  All rights reserved.</h5><br></pre>
<a href=file:///tmp/httpd/.products/DEV/credits.html>Credits</a>
</b>
</form>
</body>
</html>
.

format INDEX_DEFAULT =
<html>
<title>@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< </title>
$Company
<body>
<center><img ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/sample.gif"></center>
<center><app class="DancingText" font=TimesRoman30b text="This is an example of a main page!" time=2000 pause=1500></center>
<h1>@*
$Company
</h1><p>@*
$Description
<h4>@*
$Product
: You could indicate here the description of your product(s)</h4>
<p>You can create other HTML pages that people will access through this page, to provide details about your products, prices, distributors, events where your company will be present....</p>
<hr><b>
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$Company
</b><br>Street number and name<br>
City, St Zip<br>
Country.<br>
Phone: (area)....<br>
Fax: (area)...<br>
<h5>To contact our sales services or ask for more information:<A HREF="mailto:@*
$Email
">@*
$Email
</A></H5>
<h5>To visit our web site:<A HREF="http://@*
$WebSite
">http://@*
$WebSite
/</A></H5>
<body><html>
.

format ADVICES =
<H2><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_pink.gif"><a href="file://@*
"$HomeDir/$HomeName"
">To test your main page and links</a></H2><br>
<ul><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/finger.gif">To change your pages, you need to edit the html files that you put in the "@*
$HomeDir
" directory or one of its subdirectories. To do that, you can either use a text editor to directly change the content of the file or one of the numerous tools that exist.
<p><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/finger.gif">If you visit your html pages, you can come back any time to the main menu of the Developer's Kit by using the "<b>Goto</b>" Menu.<br>
<p><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/finger.gif">If a link or an image doesn't work when you visit it, it might be because the <b>path</b> you set is incorrect. The correct types of paths are:<br>
<ul>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><b>Relative path</b>: images/test.gif or ../docs/toc.html<br>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><b>Web address</b>: http://www.sun.com/index.html or http://www.xm.com/cafe/<br>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><b>Absolute path (using the http server)</b>: http://localhost:7999/DIRNAME/welcome.htm or http://localhost:7999/DIRNAME/images/test.gif, where DIRNAME is the name of your company directory.<br>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><b>Absolute path (using the file server)</b>: file:///tmp/httpd/.products/DIRNAME/welcome.html or file:///tmp/httpd/.products/DIRNAME/images/test.gif.<br>
</ul>
</ul><br>
#<H2><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_pink.gif"><a href="file:///tmp/httpd/.products/DEV/tips.html">Help and tips for designing your insertion</a></H2></ul><br>
<H2><IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_pink.gif"><a href="http://localhost:7999/cgi-bin/visit_html.pl#TIPS">Help and tips for designing your insertion</a></H2></ul><br>
.

format SUBPAGE =
<hr>
<A NAME="TIPS">
<h1>Tips</h1>
<ol type=1>
#<li><IMG ALIGN=middle SRC="file:///tmp/httpd/.products/DEV/images/u_constr.gif"><a href="file:///tmp/httpd/.products/DEV/maps.html">How to use links with area of images</a><br>
#<li><IMG ALIGN=middle SRC="file:///tmp/httpd/.products/DEV/images/u_constr.gif"><a href="http://localhost:7999/cgi-bin/visit_html.pl#MAPS">How to use links with area of images</a><br>
<li><a href="http://localhost:7999/cgi-bin/visit_html.pl#MAPS">How to use links with area of images</a><br>
#<li><IMG ALIGN=middle SRC="file:///tmp/httpd/.products/DEV/images/u_constr.gif"><a href="file:///tmp/httpd/.products/DEV/applets.html">Where to get Applets</a><br>
<li><a href="http://www.sun.com/styleguide/">Style guide for HTML pages</a>
#<li><a href="http://localhost:7999/cgi-bin/visit_html.pl#TRANS">How to use transparent images</a><br>
</ol>
</b>
<hr>
<A NAME="MAPS">
<h1>How to use links with area of images</h1>
It is possible to use <b>maps</b>. These allow you to go to a new page by clicking on some areas of an image. You need to follow these steps:
<ol>
<li>Insert in your HTML file a reference to your image and a <i>mapfile</i>. (ex:<br>
<ul><tt>&lt;A HREF="http://localhost:7999/cgi-bin/imagemap/DIRNAME/test.map"&gt; &lt;IMG SRC="./test.gif" ISMAP&gt;</tt><br>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/finger.gif"><b>You need to use an absolute path using the http server!</b><br></ul>
<li>create your mapfile. You need to indicate a default URL, and the areas that you want the user to reach. (ex:
<ul><br>
<tt>default file:///tmp/httpd/.products/DIRNAME/index.html<br>
rect    file:///tmp/httpd/.products/DIRNAME/URL1.html  28,669 92,701<br>
rect    file:///tmp/httpd/.products/DIRNAME/URL2.html 98,669 195,703<br>
poly	file:///tmp/httpd/.products/DIRNAME/URL3.html 439,328 466,288 485,302 453,333<br>
circle	file:///tmp/httpd/.products/DIRNAME/URL4.html 299,153 397,153<br>
</tt>
</ul>
</ol>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/finger.gif">In maps files, you need to use <b><i>absolute paths</b></i>, such as:<br>
<ul>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><b>Absolute path (using the http server)</b>: http://localhost:7999/DIRNAME/welcome.htm or http://localhost:7999/DIRNAME/images/test.gif, where DIRNAME is the name of your company directory.<br>
<IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif"><b>Absolute path (using the file server)</b>: file:///tmp/httpd/.products/DIRNAME/welcome.html or file:///tmp/httpd/.products/DIRNAME/images/test.gif.<br>
</ul>
<A NAME="TRANS">
#<h1>How to use transparent images</h1>
#It is possible to use <b>maps</b>. These allow you to go to a new page by clicking on some areas of an image. You need to follow these steps:
</body>
</html>
.
